<?php
/**
 * Created by PhpStorm.
 * User: 轩
 * Date: 2017/9/4
 * Time: 18:08
 */
namespace app\home\controller\Cloud;
use think\Db;
use think\Session;
use think\Controller;
use app\home\service\AccountService;

class Brand extends Controller
{
    private $MINI_ID;
    private $WX_id;
    private $WX_secret;

    public function _initialize()
    {
        parent::_initialize();
        $A = new AccountService();
        $this->MINI_ID = Session::get('login_miniID');
        $this->WX_id = $A->getminiAppsData('appid', $this->MINI_ID);
        $this->WX_secret = $A->getminiAppsData('secret', $this->MINI_ID);
    }

    public function index()
    {
        $CONFIG = [
            'title'=>'品牌功能',
            'css'=>[

            ],
            'js'=>[

            ],
            'path'=>[
                '品牌管理'
            ],
        ];
        $this->assign('CONFIG',$CONFIG);
        $DATA = Db::table('temp_cd_brand')->where('miniapps_id',$this->MINI_ID)->select();
        $this->assign('DATA',$DATA);
        return $this->fetch('_Tpl/cloud/brand');
    }

    public function addbrand()
    {
        $data = [
            'title'=>input('title'),
            'add_time'=> date('y-m-d H:i:s',time()),
            'miniapps_id'=>$this->MINI_ID,
        ];
        $res = Db::table('temp_cd_brand')->insert($data);
        if($res){
            $arr['info'] = 1;
            return $arr;
        }else{
            $arr['info'] = 0;
            return $arr;
        }
    }

    public function savebrand()
    {

        $data = [
            'id'=>input('id')
        ];
        $arr = [
            'title'=>input('title')
        ];
        $res = Db::table('temp_cd_brand')->where($data)->update($arr);
        if($res){
            $arr['info'] = 1;
            return $arr;
        }else{
            $arr['info'] = 0;
            return $arr;
        }
    }

    public function delbrand()
    {
        $data = [
            'id'=>input('id'),
        ];

        $res = Db::table('temp_cd_brand')->where($data)->delete();
        if($res){
            $arr['info'] = 1;
            return $arr;
        }else{
            $arr['info'] = 0;
            return $arr;
        }
    }
}
?>